package com.gitee.huxing.course.conc.task;

import java.util.concurrent.FutureTask;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.conc.task
 * @ClassName: TaskService01Impl
 * @Author: huxing
 * @DateTime: 2021-08-25 下午4:58
 */
public class TaskThreadPool02 extends AbstractTaskThreadPool{

    public static void main(String[] args) throws InterruptedException{
        new TaskThreadPool02().task();
    }

    @Override
    public int threadTask() {
        // 定义一个变量
        final int[] result = new int[1];
        new Thread(() -> result[0] = CourseTask.sum()).start();
        // 当活跃线程只有一个的时候返回
        while (Thread.activeCount() != 1){
            try {
                Thread.sleep(1000L);
            } catch (Exception ex){
                ex.printStackTrace();
            }
        }
        return result[0];
    }
}
